<template>
  <div class="feedback-container">
    <!-- 欢迎语 -->
    <div class="welcome-banner">
      <h1>{{ $t('welcomeTitle') }}</h1>
      <p>{{ $t('welcomeContent') }}</p>
    </div>
    
    <!-- 反馈类型选择 -->
    <div class="section feedback-type">
      <h2 class="section-title">
         <i class="icon-type"></i>
         {{ $t('feedbackTypeTitle') }}
      </h2>
      <div class="type-selector">
        <button 
  v-for="type in feedbackTypes" 
  :key="type.value"
  @click="selectFeedbackType(type.value)"
  :class="{ active: selectedType === type.value }"
>
  {{ $t('feedbackTypes.' + type.value) }}
</button>
      </div>
    </div>
    
    <!-- 常见问题 -->
    <div class="section common-issues">
      <h2 class="section-title">
        <i class="icon-question"></i>
        {{ $t('commonIssuesTitle') }}
      </h2>
      
      <!-- 常见问题列表 -->
      <div class="issues-list">
  <div class="issue-item" v-for="(issue, index) in filteredCommonIssues" :key="index">
    <label class="issue-checkbox-container">
      <input
        type="checkbox"
        class="issue-checkbox"
        :id="'issue' + index"
        :value="issue"
        v-model="selectedIssues"
      >
      <span class="checkmark"></span>
      <span class="issue-label">{{ $t(`commonIssues.${selectedType}.${index}`) }}</span>
    </label>
  </div>
</div>
</div>
    
    <!-- 输入其他问题 -->
    <div class="section other-issues">
      <h2 class="section-title">
        <i class="icon-text"></i>
        {{ $t('otherIssuesTitle') }}
      </h2>
      
      <div class="input-wrapper">
        <textarea
          class="input-area"
          :placeholder="$t('otherIssuesPlaceholder')"
          v-model="otherIssue"
        ></textarea>
        <span class="character-count">{{ otherIssue.length }}/500</span>
      </div>
    </div>
    
    <!-- 提交按钮 -->
    <button class="submit-button" @click="submitFeedback" :disabled="isSubmitting">
      <span v-if="!isSubmitting">{{ $t('submitButtonText') }}</span>
      <span v-else>{{ $t('submittingText') }}</span>
    </button>
    
    <!-- 提交成功提示 -->
    <div class="success-message" v-if="showSuccess">
      <i class="icon-success"></i>
      <p>{{ $t('successMessage') }}</p>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      selectedType: 'suggestion', // 默认选择建议
      feedbackTypes: [
        { value: 'opinion', label: '意见' },
        { value: 'suggestion', label: '建议' },
        { value: 'complaint', label: '投诉' }
      ],
      commonIssuesByType: {
        opinion: [
         'feedback.commonIssues.opinion.0',
        'feedback.commonIssues.opinion.1',
         'feedback.commonIssues.opinion.2',
        'feedback.commonIssues.opinion.3'
        ],
        suggestion: [
          'feedback.commonIssues.suggestion.0',
            'feedback.commonIssues.suggestion.1',
              'feedback.commonIssues.suggestion.2',
                'feedback.commonIssues.suggestion.3'
        ],
        complaint: [
          'feedback.commonIssues.complaint.0',
          'feedback.commonIssues.complaint.1',
          'feedback.commonIssues.complaint.2',
          'feedback.commonIssues.complaint.3'
        ]
      },
      selectedIssues: [],
      otherIssue: '',
      isSubmitting: false,
      showSuccess: false
    };
  },
  computed: {
    filteredCommonIssues() {
      return this.commonIssuesByType[this.selectedType] || [];
    }
  },
  methods: {
    selectFeedbackType(type) {
      this.selectedType = type;
      this.selectedIssues = []; // 切换类型时清空已选问题
    },
    submitFeedback() {
      if (this.isSubmitting) return;
      
      if (!this.selectedIssues.length && !this.otherIssue.trim()) {
        alert(this.$t('selectOrInputIssueAlert'));
        return;
      }
      
      this.isSubmitting = true;
      
      const feedbackData = {
        type: this.selectedType,
        commonIssues: this.selectedIssues,
        otherIssue: this.otherIssue
      };
      
      console.log('用户反馈数据:', feedbackData);
      
      setTimeout(() => {
        this.isSubmitting = false;
        this.showSuccess = true;
        
        this.selectedIssues = [];
        this.otherIssue = '';
        
        setTimeout(() => {
          this.showSuccess = false;
        }, 2000);
      }, 1500);
    }
  }
};
</script>

<style>
/* 全局样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
  background-color: #f5f7fa;
  color: #333;
  line-height: 1.6;
}

/* 主容器样式 - 调整为与个人信息页面一致 */
.feedback-container {
  max-width: 800px;
  margin: 2rem auto;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(74, 175, 254, 0.1);
  padding: 30px;
  border: 1px solid #e3f2fd;
  position: relative;
  overflow: hidden;
}

.feedback-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 5px;
  height: 100%;
  background: linear-gradient(to bottom, #4f8bf9, #2ac9e6);
}

/* 欢迎语样式 */
.welcome-banner {
  text-align: center;
  margin-bottom: 40px;
  padding: 20px;
  background: linear-gradient(135deg, 
    white 0%, 
    white 30%,  
    #3e92cc 60%, 
    #3e92cc 100%
  );
  border-radius: 10px;
}

.welcome-banner h1 {
  font-size: 28px;
  color: #2c3e50;
  margin-bottom: 10px;
}

.welcome-banner p {
  font-size: 16px;
  color: white;
}

/* 分区样式 */
.section {
  margin-bottom: 30px;
  background-color: #f9f9f9;
  border-radius: 10px;
  padding: 25px;
  border: 1px solid #e3f2fd;
}

.section-title {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  font-size: 20px;
  color: #2c3e50;
}

.icon-question {
  display: inline-block;
  width: 24px;
  height: 24px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%234f8bf9"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/></svg>');
  background-size: contain;
  background-repeat: no-repeat;
  margin-right: 10px;
}

.icon-text {
  display: inline-block;
  width: 24px;
  height: 24px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%234f8bf9"><path d="M4 9h16v6H4V9zm0-4h16v6H4V5z"/></svg>');
  background-size: contain;
  background-repeat: no-repeat;
  margin-right: 10px;
}

/* 常见问题列表样式 */
.issues-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 15px;
}

.issue-item {
  background-color: #fff;
  border-radius: 8px;
  padding: 15px;
  border: 1px solid #e3f2fd;
}

.issue-checkbox-container {
  display: block;
  position: relative;
  padding-left: 30px;
  cursor: pointer;
  font-size: 16px;
  user-select: none;
}

.issue-checkbox {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 22px;
  width: 22px;
  background-color: #eee;
  border-radius: 4px;
  transition: all 0.3s;
}

.issue-checkbox:checked ~ .checkmark {
  background-color: #4f8bf9;
  transform: scale(1.1);
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.issue-checkbox:checked ~ .checkmark:after {
  display: block;
  left: 8px;
  top: 4px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.issue-label {
  display: block;
  margin-top: 3px;
  color: #555;
}

/* 输入区域样式 */
.input-wrapper {
  position: relative;
}

.input-area {
  width: 100%;
  min-height: 150px;
  background-color: #fff;
  border: 1px solid #e3f2fd;
  border-radius: 8px;
  padding: 15px;
  resize: vertical;
  font-family: inherit;
  font-size: 16px;
  color: #333;
}

.input-area:focus {
  outline: none;
  border-color: #4f8bf9;
  box-shadow: 0 0 0 3px rgba(79, 139, 249, 0.2);
}

.character-count {
  position: absolute;
  bottom: 10px;
  right: 10px;
  font-size: 12px;
  color: #999;
}

/* 提交按钮样式 */
.submit-button {
  width: 100%;
  padding: 15px;
  background-color: #4f8bf9;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
}

.submit-button:hover {
  background-color: #3a7ae8;
}

.submit-button:disabled {
  background-color: #b3c6ff;
  cursor: not-allowed;
}

/* 提交成功提示 */
.success-message {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #f1f9ea;
  color: #2e7d32;
  padding: 20px 30px;
  border-radius: 8px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 15px;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    transform: translateX(-50%) translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateX(-50%);
    opacity: 1;
  }
}
.icon-type {
  display: inline-block;
  width: 24px;
  height: 24px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%234f8bf9"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 13h2v2h-2zm0-8h2v6h-2z"/></svg>');
  background-size: contain;
  background-repeat: no-repeat;
  margin-right: 10px;
}

.icon-success {
  display: inline-block;
  width: 24px;
  height: 24px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%232e7d32"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93L5.83 12l1-1.07 4.17 4.17L19 7l-1-1.07L11 18.93z"/></svg>');
  background-size: contain;
  background-repeat: no-repeat;
}
.type-selector {
  display: flex;
  gap: 15px;
  margin-top: 15px;
}

.type-selector button {
  flex: 1;
  padding: 12px;
  background-color: #f0f4ff;
  border: 1px solid #e3f2fd;
  border-radius: 8px;
  color: #4f8bf9;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s;
}

.type-selector button:hover {
  background-color: #e1ecff;
}

.type-selector button.active {
  background-color: #4f8bf9;
  color: white;
  border-color: #4f8bf9;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .feedback-container {
    margin: 20px;
    padding: 20px;
  }
  
  .welcome-banner h1 {
    font-size: 24px;
  }
  
  .section-title {
    font-size: 18px;
  }
  
  .issues-list {
    grid-template-columns: 1fr;
  }
}
</style>